package base.tree.imageTree;

import base.tree.TreeNode;


public class Solution {

    /**
     * �ж��Ƿ��ǶԳƶ�����
     */
    public boolean isSymmetric(TreeNode root) {
        if (root==null) return true;

        return isSymmetric2(root.left,root.right);
    }

    public boolean isSymmetric2(TreeNode root1,TreeNode root2){
        if (root1==null&&root2==null) return true;

        if (root2==null || root1==null || root2.val!=root1.val) return false;

        return isSymmetric2(root1.left,root2.right) && isSymmetric2(root1.right,root2.left);
    }

    /**
     * �ж������������Ƿ����
     */
    public static boolean isEqual(TreeNode node1,TreeNode node2){

        if (node1 == null && node2 == null) {
            return true;
        }
        if ((node1 == null && node2 != null)) {
            return false;
        }
        if ((node1 != null && node2 == null)) {
            return false;
        }
        if (!(node1.val==node2.val)) {
            return false;
        }
        return isEqual(node1.left, node2.left) && isEqual(node1.right, node2.right);
    }
}
